package com.jt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ProviderApp {
    //创建java中的日志对象(SLF4J是Java中的日志规范,是日志对外的窗口是门面)
    private static final Logger log = LoggerFactory.getLogger(ProviderController.class);
    public static void main(String[] args) {
        SpringApplication.run(ProviderApp.class,args);
    }
    /**定义Controller对象(这个对象在spring mvc中给他的定义是handler),
     * 基于此对象处理客户端的请求*/
    @RestController
    @RefreshScope//这个注解描述类时,当配置中心数据发生变化会对属性重新.初始化
    public class ProviderController{
        //@Value默认读取项目配置文件中配置的内容
        @Value("${server.port:8080}")
        private String server;
        @Value("${logging.level.com.jt}")
        private String loglevel;
        @Value("${server.tomcat.threads.max:200}")
        private Integer maxThread;
        //http://localhost:8080/provider/echo/tedu
        @GetMapping("/provider/echo/{msg}")
        public String doRestEcho1(@PathVariable String msg) {

            //Thread.sleep(50000);\
           log.trace("trace");
           log.debug("debug");
           log.info("info");
           log.warn("warn");
           log.error("error");
            //return server+" say hello "+msg;
            return "log"+loglevel;
        }
        //http://localhost:8080/provider/doGetMaxThread
        @RequestMapping("/provider/doGetMaxThread")
        public String doGetMaxThread(){

            return "server.threads.max is  "+maxThread;
        }
        @Value("${page.pageSize:10}")
        private Integer pageSize;
        //http://localhost:8091/provider/doGetPageSize
        @GetMapping("/provider/doGetPageSize")
        public String doGetPageSize(){
            //return String.format()
            return "sever"+server;
        }

    }
}
